package com.keydom.ropeskipping;

import android.app.Activity;
import android.app.Application;
import android.os.ParcelUuid;

import com.clj.fastble.BleManager;
import com.keydom.ropeskipping.utils.LogLocalUtils;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

public class AppApplication extends Application {
    //运用list来保存们每一个activity是关键
    private List<Activity> mList = new LinkedList<Activity>();
    private static AppApplication instance;
    private static List<ParcelUuid> bluetoothUuid;
    public String historyUrl;
    /**
     * 保存列表数据（如果未发生变化，不去刷新页面）
     */
    public String listData;

    public void setBluetoothUuid(List<ParcelUuid> bluetoothUuid) {
        AppApplication.bluetoothUuid = bluetoothUuid;
    }

    public List<ParcelUuid> getBluetoothUuid() {
        return bluetoothUuid;
    }

    public static AppApplication getInstance() {
        // 因为我们程序运行后，Application是首先初始化的，如果在这里不用判断instance是否为空
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        BleManager.getInstance().init(this);

        //开启全局错误日志捕获
//        LogLocalUtils.openErrorCatch();
//        LogLocalUtils.startAppRecord();
    }

    // add Activity
    public void addActivity(Activity activity) {
        mList.add(activity);
    }

    //关闭每一个list内的activity
    public void exit() {
        try {
            for (Activity activity:mList) {
                if (activity != null)
                    activity.finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }

    //杀进程
    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }
}
